package ImageRotationMovement;

import java.awt.Dimension;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;


public class RotateTest {
	public static void main(String[] args) throws IOException, InterruptedException{
		JFrame frame = new JFrame("Test");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		File imgfile = new File("src/Dinosaur.png");
		BufferedImage img = ImageIO.read(imgfile);
		
		
		Dinosaur test = new Dinosaur(img);
		frame.add(test);
		frame.pack();
		frame.setSize(new Dimension(500,500));
		frame.setVisible(true);
		
		frame.addKeyListener(new Charles(test, frame));
		}
	}

	class Charles implements KeyListener{
		Dinosaur test;
		JFrame frame;
		
		public Charles(Dinosaur test, JFrame frame){
			this.test = test;
			this.frame = frame;
		}
		
		public void keyPressed(KeyEvent e){
			
			System.out.println(e.getKeyCode());
			if (e.getKeyCode() == KeyEvent.VK_RIGHT){
				//System.out.println("right pressed");
				test.rotateRight();
			}
			
			if (e.getKeyCode() == KeyEvent.VK_LEFT){
				//System.out.println("left pressed");
				test.rotateLeft();
			}
			
			if (e.getKeyCode() == 87){
				test.moveUp();
			}
			
			if (e.getKeyCode() == 65){
				test.moveLeft();
			}
			
			if (e.getKeyCode() == 83){
				test.moveDown(frame.getHeight()*2);
			}
			
			if (e.getKeyCode() == 68){
				test.moveRight(frame.getWidth()*2);
			}
				
			
	}

		@Override
		public void keyReleased(KeyEvent e) {
			
		}

		@Override
		public void keyTyped(KeyEvent e) {
			
		}
}
